package cn.ondraw.system.util;

import org.apache.commons.lang3.RandomStringUtils;

import java.security.SecureRandom;
import java.util.UUID;

/**
 * @author https://www.wdbyte.com
 */
public class KeyUtils {

    private static final ThreadLocal<SecureRandom> SECURE_RANDOM =
        ThreadLocal.withInitial(SecureRandom::new);

    private static String generateSecureAlphanumeric(int length) {
        return RandomStringUtils.random(
            length, 0, 0, true, true, null, SECURE_RANDOM.get()
        );
    }

    public static String key6() {
        return generateSecureAlphanumeric(6);
    }

    public static String key16() {
        return generateSecureAlphanumeric(16);
    }

    public static String uuid32() {
        return UUID.randomUUID().toString().replace("-", "");
    }

}
